#include <iostream>
#include <map>
#include <cmath>
using namespace std;

bool is_prime(int n)
{
    for (int i=2;i<(int)(sqrt(n) + 1); i++)
    {
        if (n%i==0)
        {
            return 0;
        }
    }
    return 1;

}



int main()
{
    int x1,x2,r,f;
    string q,v;
    string w = "";
    string num = "";
    string m[10] {"zero","one","two","three","four","five","six","seven","eight","nine"};
    map <string, string> d = {
        {"zero","0"}, {"one","1"}, {"two","2"}, {"three","3"}, {"four","4"}, {"five","5"}, {"six","6"}, {"seven","7"}, {"eight","8"}, {"nine","9"},
    };

    getline(cin, q);


    int i = 0;
    while (i < (int)q.size())
    {
        while (q[i] == ' ')
        {
            i++;
        }
        w = "";
        while (i < (int)q.size() and q[i] != ' ')
        {
        w = w  + q[i];
        i++;
        }
        for (int i=0;i<10;i++)
        {
            if (m[i] == w)
            {
                f=1;
            }
        }
        if (f==1)
        {
            num = num + d[w];
            f=0;
        }
        else
        {
            cout<<"Wrong input";
            exit(0);
        }
    }

    int n = stoi(num);
    if (n > 99 and n < 1000)
    {
        for (int x=n; x<n*1000; x++)
        {

            if (is_prime(x))
            {
                x1=x;
                break;
            }
        }

        for (int z=n; z>2; z--)
        {
            if (is_prime(z))
            {
                x2=z;
                break;
            }
        }

        if ((x1-n) > (n - x2))
        {
            cout<<x2;
        }

        if ((n - x2) > (x1-n))
        {
            cout<<x1;
        }
    }
    else
    {
        cout<<"Wrong input";
    }

}
